<template>
	<view>
		<scan></scan>
		<scanner></scanner>
		<sm></sm>
		<honeywell></honeywell>
		<hk></hk>
		<view class=" u-p-r-30 u-p-l-30 u-m-t-20">
			<u-search placeholder="请输入关键词搜索" v-model="keyword" :clearable="true"  @input="onInputChange"
				border-color="#606266" @custom="search" @search="search"></u-search>
		</view>
		<u-card padding="16" v-for="(item,index) in dataList" :key="index" @click="toGoods(item)">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="7">
							<view class="u-m-t-5 weikaishi3 lanse">
								<span><u-icon name="order" size="30" labelSize="15px"
										labelColor="#000000"></u-icon>{{item.storageNumber}}</span>
							</view>
						</u-col>
						<u-col span="5" text-align="right" v-if="item.realNum > 0">
							<view class="u-m-t-5 jinxingzhong weikaishi3">
								<span>正在收货</span>
							</view>
						</u-col>
						<u-col span="5" text-align="right" v-else>
							<view class="u-m-t-5 weikaishi3">
								<span>未收货</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12">
							<view class="weikaishi3">
								<span><u-icon name="account" size="29" labelSize="14px" labelColor="#000000"
										label="发货客户" color="#000000"></u-icon>：{{item.setUnit}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12">
							<view class="weikaishi3">
								<span><u-icon name="home" size="29" labelSize="14px" labelColor="#000000"
										label="收货仓库"></u-icon>：{{item.getWarehouse}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="7">
							<view class="weikaishi6">
								<span><u-icon name="clock" size="29" labelSize="14px" labelColor="#000000" label="数量"
										color="#000000"></u-icon>：{{item.putNum}}/{{item.putVolume}}方</span>
							</view>
						</u-col>
						<u-col span="5" v-if="item.putNum == item.realNum">
							<view class="weikaishi6 yiwancheng">
								<span><u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#00c300"
										label="实入" color="#00c300"></u-icon>：{{item.realNum}}</span>
							</view>
						</u-col>
						<u-col span="5" v-else>
							<view class="weikaishi6">
								<span><u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#000000"
										label="实入" color="#000000"></u-icon>：{{item.realNum}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12">
							<view class="weikaishi6">
								<span><u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#000000"
										label="商品数"></u-icon>：{{item.goodsNum}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12">
							<view class="weikaishi6">
								<span><u-icon name="calendar" size="29" labelSize="14px" labelColor="#000000"
										label="预约时间"></u-icon>：{{item.yuyueTime}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</u-card>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>
<script>
	
	import scan from "@/components/uni-scan/scan.vue"
	import scanner from "@/components/uni-scan/scanner.vue"
	import sm from "@/components/uni-scan/sm.vue"
	import honeywell from "@/components/uni-scan/honeywell.vue"
	import hk from "@/components/uni-scan/hk.vue"
	
	// 防抖函数定义
	function debounce(func, wait) {
	  let timeout;
	  return function() {
	    const context = this,
	          args = arguments;
	    clearTimeout(timeout);
	    timeout = setTimeout(function() {
	      func.apply(context, args);
	    }, wait);
	  };
	}
	export default {
		components: {
			scanner,
			scan,
			sm,
			honeywell,
			hk
		},
		data() {
			return {
				dataList: [],
				keyword: '',
			}
		},
		onLoad() {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif
		},
		onShow() {
			this.refresh()
			let that = this
			uni.$off('scan')
			uni.$on('scan', function(res) {
				console.log('扫码结果：', res.codeStr);
				that.keyword = res.codeStr;
				that.refresh();
			})
			uni.$off('scanner') // 每次进来先 移除全局自定义事件监听器
			uni.$on('scanner', function(res) {
				console.log('扫码结果：', res.code);
				that.keyword = res.code;
				that.refresh();
			})
			uni.$off('sm') // 每次进来先 移除全局自定义事件监听器
			uni.$on('sm', function(res) {
				console.log('扫码结果：', res.code);
				that.keyword = res.code;
				that.refresh();
			})
			uni.$off('honeywell') // 每次进来先 移除全局自定义事件监听器
			uni.$on('honeywell', function(res) {
				console.log('扫码结果：', res.code);
				that.keyword = res.code;
				that.refresh();
			})
			uni.$off('hk') // 每次进来先 移除全局自定义事件监听器
			uni.$on('hk', function(res) {
				console.log('扫码结果：', res.code);
				that.keyword = res.code;
				that.refresh();
			})
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		methods: {
			onInputChange(value) {
			      this.keyword = value;
			    },
				debouncedUpdateKeyword: debounce(function(value) {
				      this.keyword = value;
				     // console.log('更新关键词:', this.keyword);
				    }, 300),
			toGoods(e) {
				this.$Router.push({
					name: 'hx_storage_put_quality_goods',
					params: {
						storageNumber: e.storageNumber
					},
				})
			},
			refresh() {
				uni.showLoading({
					title: '加载中...'
				})
				this.$http.post('/rest/HxStoragePut/storagelist', {}, {
					params: {
						keyword: this.keyword,
					},
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					this.dataList = res.data.data
					// if(this.dataList.length === 1){
					// 	this.toGoods(this.dataList[0]);
					// }
				})
				uni.hideLoading()
			},
			search(e) {
				this.refresh()
			},
		},
	}
</script>